package cc.rengu.igas.share.common.dao.impl;

import cc.rengu.igas.share.common.dao.HolidayInfoMapper;
import cc.rengu.igas.share.common.entity.HolidayInfo;
import cc.rengu.jradp.mods.dbs.Database;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;


/**
 * dao接口实现
 *
 * @author Administrator
 * @version 1.0
 * @date 2019/10/15
 */
public class HolidayInfoMapperImpl implements HolidayInfoMapper {
    private final RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);

    @Override
    public boolean isHoliday(String date) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.CSMC_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "csmcSelectHolidayFlagByDate");

        HolidayInfo holidayInfoObj = new HolidayInfo();
        holidayInfoObj.setBatchDate(date);
        int ret = dbsUtil.dbsExecuteSql(sqlStr, holidayInfoObj, holidayInfoObj);
        if (ret != Database.DBS_SUCCESS) {
            rglog.error("查询节假日表失败");
            throw new Exception("查询节假日表失败");
        } else {
            return "y".equalsIgnoreCase(holidayInfoObj.getHolidayFlag());
        }
    }
}
